﻿@{
    ViewBag.Title = "过期物资列表";
    Layout = "~/Areas/IM/Views/Shared/_Layout.cshtml";
}
<script src="~/Scripts/print.js"></script>
@section scripts{
    <script type="text/javascript">
        var boolSearch = true;
        //页面初始化
        $(document).ready(function () {
            initPage();
            bindGrid();
            DisableBackspace();
        })
        $(window).resize(function () {
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridOverdueMList");
        });
        //页面初始化加载
        function initPage() {
            $('#remainTime').slider({
                showTip: true,
                max: 180,
                rule: [0, '|', 30, '|', 60, '|', 90, '|', 120, '|', 150, '|', 180],
                tipFormatter: function (value) {
                    return value + '天';
                },
                onChange: function (value) {
                    $('#remainTime').val(value);
                }
            });
            var urlstr1 = '@Url.Content("~/IM/AllDictionary/GetStorageCombo")';
            $.EUIcombobox("#Storage", {
                url: urlstr1,
                valueField: 'ID',
                textField: 'Name',
                editable: false,
                panelHeight: 'auto',
                datainfo: {},
                OneOption: [{
                    ID: "",
                    Name: "--请选择--"
                }]
            });

            var urlstr2 = '@Url.Content("~/IM/AllDictionary/GetMaterialTypeByUserInfo")';
            $.EUIcomboboxTree("#MaterialType", {
                url: urlstr2,//ajax后台取数据路径，返回的是json格式的数据
                OneOption: [{
                    id: "",
                    text: "--请选择--",
                }],
                datainfo: {},
                onSelect: function (rec) {
                    var urlstr3 = '@Url.Content("~/IM/AllDictionary/GetMaterial?mType=")' + rec.id;
                    $("#MaterialTypeInfo").val(rec.id);
                    $("#Material").combogrid({
                        prompt: '--请选择--',
                        panelWidth: 320,
                        idField: 'ID',
                        textField: 'Name',
                        groupField: 'QRCode',
                        columns: [[
                            { field: 'MCode', title: '代码', width: 50, align: 'right' },
                            { field: 'Name', title: '名称', width: 100 },
                            { field: 'UnitName', title: '单位', width: 50 },
                            { field: 'Specification', title: '规格', width: 50, align: 'right' },
                            { field: 'RealPrice', title: '售价', width: 50 },
                            { field: 'Unit', title: '单位', width: 50, sortable: false, hidden: true }
                        ]],
                        fitColumns: true,
                        filter: function (inputText, row) {
                            var opts = $(this).combogrid('options');
                            if (row[opts.groupField] == inputText) {
                                return true;
                            } else if (row[opts.textField] == inputText) {
                                return true;
                            } else {
                                if (boolSearch) {
                                    boolSearch = false;
                                    searchBindMeterialbyName(urlstr3, inputText);
                                }
                            }
                        },
                        onChange: function (n, o) {
                            if (n == "") {
                                searchBindMeterialbyName(urlstr3, n);
                                $("#MaterialID").val("");
                            }
                        },
                        onSelect: function (rec) {
                            var g = $("#Material").combogrid("grid");	// 获取数据表格对象
                            var r = g.datagrid('getSelected');	// 获取选择的行
                            $("#MaterialID").val($('#Material').combobox('getValue'));

                        }
                    });
                    searchBindMeterialbyName(urlstr3, "");
                }
            });
        }
        //重新查询
        function reSearch() {
            $('#gridOverdueMList').datagrid({
                pageNumber: 1,//20151105增加点击查询按钮返回第一页
                queryParams: {
                    remainTime: $('#remainTime').val(),
                    MaterialType: $("#MaterialTypeInfo").val(),
                    MaterialID: $("#MaterialID").val(),
                    StorageCode: $("#Storage").combobox("getValue")
                }
            });
            $('#gridOverdueMList').datagrid('reload');
        }
        //初始化查询
        function bindGrid() {
            $('#gridOverdueMList').datagrid({
                width: 'auto',
                height: 'auto',
                fitColumns: true,
                singleSelect: true,
                loadMsg: '数据加载中请稍后……',
                url: '@Url.Content("~/OverdueMaterial/DataLoad")',
                autoRowHeight: true,
                striped: true,
                pagination: true,//启用分页，默认每页10行
                rownumbers: true,//显示页码，默认 提供 10 - 50 的页容量选择下拉框
                pageSize: 10,//设置 页容量5为
                pageList: [10, 15, 20],//设置 页容量下拉框
                queryParams: {
                    remainTime: $("#remainTime").val(),
                    MaterialType: $("#MaterialTypeInfo").val(),
                    MaterialID: $("#MaterialID").val(),
                    StorageCode: $("#Storage").combobox("getValue")
                },
                columns: [[
                    //{ field: 'ck', checkbox: true },
                    { field: "StorageName", title: "所属仓库", width: '13%', align: "center" },
                    { field: "MaterialName", title: "物资名称", width: '15%', align: "center" },
                    { field: "RealBatchNo", title: "批次号", width: '10%', align: "center", formatter: $.formatRealBatchNo },
                    //{ field: "ValidityDate", title: "有效期", width: '10%', align: "center", sortable: true, formatter: $.formatValidityDate },
                    { field: "MaterialManufacturer", title: "生产厂家", width: '10%', align: "center" },
                    { field: "MaterialVendor", title: "供应商", width: '12%', align: "center" },
                    { field: "MaterialUnitName", title: "单位", width: '5%', align: "center" },
                    { field: "MaterialSpecification", title: "规格", width: '5%', align: "center" },
                    { field: "EntryCounts", title: "入库总量", width: '7%', align: "center" },
                    { field: "Surplus", title: "库存量", width: '8%', align: "center" },
                    { title: 'ID', field: 'ID', sortable: false, hidden: true },
                    { title: 'StorageCode', field: 'StorageCode', sortable: false, hidden: true },
                    { title: 'MaterialID', field: 'MaterialID', sortable: false, hidden: true },
                    { title: 'BatchNo', field: 'BatchNo', sortable: false, hidden: true },
                    { title: 'MaterialMTypeID', field: 'MaterialMTypeID', sortable: false, hidden: true },
                    { title: 'MaterialAlarmCounts', field: 'MaterialAlarmCounts', sortable: false, hidden: true }
                ]],
                rowStyler: function (index, row) {
                    if ($.formatValidityDateToDateTime(row.ValidityDate) <= $.GetFuture(30)) {
                        return 'background-color:red;color:white';
                    } else if ($.formatValidityDateToDateTime(row.ValidityDate) <= $.GetFuture(90)) {
                        return 'background-color:yellowgreen;color:white';
                    } else if ($.formatValidityDateToDateTime(row.ValidityDate) <= $.GetFuture(180)) {
                        return 'background-color:blue;color:white';
                    } else if ($.formatValidityDateToDateTime(row.ValidityDate) <= $.GetFuture(0)) {
                        return ' background-color:gray; color:white';
                    }
                },
                onSelect: function (index, row) {
                    if (row.RedEntryDetailCode == row.EntryDetailCode) {
                        $("#btnOverdueView").linkbutton({
                            text: "报废--" + row.MaterialName + "[" + $.formatValidityDate(row.ValidityDate) + "]--物资",
                        });
                    }
                },
                toolbar: [
                  {
                      id: 'btnOverdueView',
                      text: '报废物资',
                      iconCls: 'icon-custom-cGuoqi',
                      handler: function () {
                          var selected = $('#gridOverdueMList').datagrid('getSelected');
                          if (selected) {
                              //隐藏数据
                              $('#RealBatchNo').val(selected.RealBatchNo);
                              $('#BatchNo').val(selected.BatchNo);
                              $('#MaterialID').val(selected.MaterialID);
                              $('#DeliveryCounts').val(selected.Surplus);
                              $('#StorageCode').val(selected.StorageCode);
                              //显示数据
                              $('#SurplusRealBatchNo').textbox('setText', $.formatRealBatchNo(selected.RealBatchNo));
                              $('#SurplusMaterialName').textbox('setText', selected.MaterialName);
                              $('#SurplusMaterialManufacturer').textbox('setText', selected.MaterialManufacturer);
                              $('#SurplusMaterialVendor').textbox('setText', selected.MaterialVendor);
                              $('#SurplusValidityDate').textbox('setText', $.formatValidityDate(selected.ValidityDate));
                              $('#SurplusStorage').textbox('setText', selected.StorageName);
                              $('#editEntryCounts').textbox('setText', selected.Surplus);
                              $('#OverdueSurplusInfo').dialog('open');
                          } else {
                              $.messager.alert('提示', '请选择数据行', 'info', function () {
                              });
                          }
                      }
                  }
                ]
            });
            $(".datagrid-header-check").attr("disabled", "disabled");
            $.setGridWithSearchBar("#TableForm", "#SearchBar", "#gridOverdueMList");
        }
        function searchBindMeterialbyName(urinfo, keyWord) {
            $.ajax({
                type: 'POST',
                url: urinfo,
                dataType: "json",
                success: function (jsData) {
                    if (keyWord == "") {
                        $("#Material").combogrid("grid").datagrid("loadData", jsData);
                    } else {
                        for (var i = 0; i < jsData.length; i++) {
                            if (jsData[i].Name.indexOf(keyWord) < 0) {
                                if (jsData[i].MCode.indexOf(keyWord) < 0) {
                                    if (jsData[i].PinYin.indexOf(keyWord) < 0) {
                                        jsData.remove(jsData[i]);
                                        i--;
                                    }
                                }
                            }
                        }
                        $("#Material").combogrid("grid").datagrid("loadData", jsData);
                    }
                    boolSearch = true;
                }
            });
        }
    </script>
}

<div id="TableForm" class="easyui-layout" style="width:auto; height: auto; margin-left: auto; margin-right: auto">
    <div data-options="region:'center',title:'过期物资',iconCls:'icon-custom-cGuoqi'">
        <div id="SearchBar" data-options="region:'north'" style="overflow: hidden; padding: 10px">
            <table>
                <tr style="height:50px">
                    <td style="width:40px">仓库：</td>
                    <td>
                        <input id="Storage" class="easyui-combotree" data-options="required:true" style="width:160px" />
                    </td>
                    <td>分类：</td>
                    <td>
                        <input id="MaterialType" class="easyui-combobox" style="width:160px" />
                        <input id="MaterialTypeInfo" type="hidden" />
                    </td>
                    <td>物资：</td>
                    <td>
                        <input id="Material" class="easyui-combogrid" style="width:160px" />
                        <input id="MaterialID" type="hidden" />
                    </td>
                    <td>告警天数：</td>
                    <td>
                        <input id="remainTime" class="easyui-slider" value="0" style="width:220px">
                    </td>
                    <td>
                        &nbsp; &nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-search'" onclick="reSearch()">查询</a>
                    </td>
                    <td>
                        &nbsp;&nbsp;&nbsp;<a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-print'" onclick="CreateFormPage('打印测试', $('#gridOverdueMList'))">打印</a>
                    </td>
                </tr>
                <tr>
                    <td colspan="9">
                        注：
                        <span style="background-color:gray; color:white">已经过期</span> &nbsp;&nbsp;|&nbsp;&nbsp;
                        <span style="background-color:red; color:white">30天内过期</span> &nbsp;&nbsp;|&nbsp;&nbsp;
                        <span style="background-color: yellowgreen; color: white; ">90天内过期</span> &nbsp;&nbsp;|&nbsp;&nbsp;
                        <span style="background-color: blue; color: white; ">180天内过期</span>
                    </td>
                </tr>
            </table>
        </div>
        <div data-options="region:'center'" style="background: #fafafa; overflow: hidden">
            <table id="gridOverdueMList"></table>
        </div>
    </div>
</div>
@Html.Partial("~/Areas/IM/Views/OverdueMaterial/_OverdueMaterialDelivery.cshtml")
